<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "yyh_workgroup".
 *
 * @property int $id 群组ID
 * @property string $name 群组名称
 * @property int $sort 排序
 * @property string $status
 */
class Workgroup extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'yyh_workgroup';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['sort'], 'integer'],
            [['status'], 'string'],
            [['name'], 'string', 'max' => 64],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => '群组ID',
            'name' => '群组名称',
            'sort' => '排序',
            'status' => '状态',
        ];
    }

    //得到树形结构的病种数据 
    public static function getTreeData($where = '', $checked_ids_string = '')
    {
        $workgroup_array = Workgroup::find()->select('id, name')->where($where)->orderBy('sort, id')->asArray()->all();
        if ($checked_ids_string != '') {
            foreach ($workgroup_array as $i => $d) {
                if ($d['name'] == trim($checked_ids_string)) {
                    $workgroup_array[$i]['checked'] = true;
                }
            }
        }

        return $workgroup_array;
    }

    //得到病种数据 
    public static function getOptions()
    {
        $res = [];
        $workgroup_array = Workgroup::find()->select('name')->orderBy('sort, id')->asArray()->all();
        if (null != $workgroup_array && count($workgroup_array) > 0) {
            foreach ($workgroup_array as $d) {
                $res[$d['name']] = $d['name'];
            }
        }

        return $res;
    }
}
